﻿using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using BSU.GraduateWork.Data.Model;
using BSU.GraduateWork.Data.Repositories.Interfaces;
using BSU.Math.Geometry;

namespace BSU.GraduateWork.Data.Repositories
{
    public class PointRepository : BaseRepository<SolutionPoint3D, int>, IPointRepository
    {
        #region IPointRepository Members

        

        #endregion

        public void SaveAll(List<SolutionPoint3D> points)
        {
            var context = GetNewContext();
            var table = context.GetTable<SolutionPoint3D>();
            foreach (var point in points)
            {
                table.InsertOnSubmit(point);    
            }
            context.SubmitChanges();
        }

        public IList<Point4D> List(int solutioinId)
        {
            var context = GetNewContext();
            var points = context.Points3D;

            return
                points
                    .Where(x => x.SolutionId == solutioinId)
                    .Select(x => new Point4D(x.X, x.Y, x.Z, x.U, x.IsBoundary))
                    .ToList();
        }
    }
}